<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符格式判断</title>
</head>
<body>
<script>
    let str = 'leetcode';

    function wordConvert(str) {
        let trueCount = 0;
        let falseCount = 0;
        let initStr = str[0];
        for (let i = 1; i < str.length; i++) {
            if (str[i] === str[i].toUpperCase()) {
                trueCount++;
            } else if (str[i] === str[i].toLowerCase()) {
                falseCount++;
            }
        }
        if (str.length === 1) {
            return initStr === initStr.toUpperCase() || initStr === initStr.toLowerCase();
        }
        for (let i = 1; i < str.length; i++) {
            if (i === str.length - 1) {
                if (initStr === initStr.toUpperCase() && trueCount === 0) {
                    return true;
                } else return initStr + str === initStr + str.toUpperCase() || initStr + str === initStr + str.toLowerCase();
            }
        }
    }

    console.log(wordConvert(str))
</script>
</body>
</html>